//
//  THJGuessPriceVC.m
//  THJXHW
//
//  Created by 河南德艺 on 2017/7/8.
//  Copyright © 2017年 河南德艺. All rights reserved.
//

#import "THJGuessPriceVC.h"
#import "SCChart.h"
#import "ZBNetworking.h"
@interface THJGuessPriceVC ()


@property (weak, nonatomic) IBOutlet UIView *view1;
@property (weak, nonatomic) IBOutlet UIView *view2;
@property (weak, nonatomic) IBOutlet UIView *view3;
@property (weak, nonatomic) IBOutlet UILabel *lab1;
@property (weak, nonatomic) IBOutlet UILabel *lab2;
@property (weak, nonatomic) IBOutlet UILabel *lab3;



@end

@implementation THJGuessPriceVC
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    if(KIsiPhoneX){
        [self setXNavBarWithTitle:@"猜合金价"];
    }else{
        [self setNavBarWithTitle:@"猜合金价"];
    }
    self.lab1.text = @"上月";
    self.lab2.text = @"当月";
    self.lab3.text = @"下月";
    __weak typeof(self) weakself = self;
    [MBProgressHUD showMessage:@"" toView:self.view];
    [ZBRequestManager requestWithConfig:^(ZBURLRequest *request){
        request.urlString= [NSString stringWithFormat:@"http://read.thjb.net/index.php?action=app_data_forecast&type=%@",self.type];
        NSLog(@"chjj-url--%@",request.urlString);
        request.apiType=ZBRequestTypeCache;
    }  success:^(id responseObject,apiType type){
        NSDictionary * receiveData = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        [MBProgressHUD hideHUDForView:weakself.view animated:YES];
        if([receiveData[@"status"] isEqual:@"success"]){
            [weakself setCycleChartAddToView:weakself.view3 DataDic:receiveData[@"data"][@"list"][@"0"]];
            [weakself setCycleChartAddToView:weakself.view2 DataDic:receiveData[@"data"][@"list"][@"1"]];
            [weakself setCycleChartAddToView:weakself.view1 DataDic:receiveData[@"data"][@"list"][@"2"]];
        }
    } failed:^(NSError *error){
        
    }];
    
    
}
-(void)setCycleChartAddToView:(UIView*)view DataDic:(NSDictionary*)dic{
        NSNumber * total =[NSNumber numberWithInteger:[dic[@"amount"] integerValue]];
        NSNumber * nm1 = [NSNumber numberWithInteger:[dic[@"up"] integerValue]];
        NSNumber * nm2 = [NSNumber numberWithInteger:[dic[@"down"] integerValue]];
        NSNumber * nm3 = [NSNumber numberWithInteger:[dic[@"flat"] integerValue]];
        
        SCCircleChart* chartView11 = [[SCCircleChart alloc] initWithFrame:CGRectMake(40, 40, 40, 60)
                                                                    total:total
                                                                  current:nm1
                                                                clockwise:YES
                                                                   shadow:YES
                                                              shadowColor:COLOR(235, 240, 237, 1.0)];
        chartView11.total = total;
        chartView11.current = nm1;
        
        [chartView11 setStrokeColor:COLOR(251, 44, 8, 1.0)];
        chartView11.chartType = SCChartFormatTypeNone;
        chartView11.format = @"看涨\n%d%%";
        [chartView11 strokeChart];
        [view addSubview:chartView11];
        
        SCCircleChart* chartView22 = [[SCCircleChart alloc] initWithFrame:CGRectMake((ScreenWidth-40)/2, 40, 40, 60)
                                                                    total:total
                                                                  current:nm2
                                                                clockwise:YES
                                                                   shadow:YES
                                                              shadowColor:COLOR(235, 240, 237, 1.0)];
        [chartView22 setStrokeColor:COLOR(11, 173, 54, 1)];
        chartView22.chartType = SCChartFormatTypeNone;
        chartView22.format = @"看跌\n%d%%";
        [chartView22 strokeChart];
        [view addSubview:chartView22];
        
        
        SCCircleChart* chartView33 = [[SCCircleChart alloc] initWithFrame:CGRectMake(ScreenWidth-80, 40, 40, 60)
                                                                    total:total
                                                                  current:nm3
                                                                clockwise:YES
                                                                   shadow:YES
                                                              shadowColor:COLOR(235, 240, 237, 1.0)];
        [chartView33 setStrokeColor:COLOR(11, 173, 54, 1)];
        chartView33.chartType = SCChartFormatTypeNone;
        chartView33.format = @"看平\n%d%%";
        [chartView33 strokeChart];
        [view addSubview:chartView33];
    

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end
